package com.ckg.service.impl;

import com.ckg.service.InventoryService;

import java.util.concurrent.atomic.AtomicInteger;

public class InventoryServiceImpl implements InventoryService {
    //    private int stock = 100; // 商品库存（有状态）
    //    解决线程安全问题
    private final AtomicInteger stock = new AtomicInteger(100);

    public void reduceStock() {
        int current = stock.decrementAndGet();  //原子操作
        System.out.println("库存减少，剩余: " + current);
    }
}
